# -*- coding:utf-8 -*-


import os
"""
整理剪映软件将语音转成文字后 整理一行
"""

def ConvertWenZi():
    # 整理时间轴与文字一行
    with open('录音文件.txt', 'r', encoding='utf-8') as file:
        line = file.readline()
        while line:
            # 处理每一行的代码
            count = line.split(',').__len__()
            strTarget = ''

            if count > 1:
                strTarget = line.split(',')[0]
                line = file.readline()
                strTarget += "  " + line.replace('\n', "")
            else:
                strTarget = line.replace('\n', '')

            with open("录音结果.txt", "a", encoding="utf-8") as fp:
                fp.write(strTarget + '\n')

            print(strTarget)

            line = file.readline()

def ConvertWenHangHao():
    # 修改文字的行号
    with open('录音结果.txt', 'r', encoding='utf-8') as file:
        line = file.readline()
        lineNum = 1
        while line:
            # 处理每一行的代码
            count = line.split(' ').__len__()
            strTarget = ''

            if count > 1 or line.replace('\n', '').isdigit():
                if count > 1:
                    strTarget = line.split(' ')[0]
                else:
                    strTarget = line.replace('\n', '')

                if strTarget.isdigit():
                    strTarget = line.replace(strTarget, str(lineNum))
                    lineNum += 1
                    strTarget = strTarget.replace('\n', "")
                else:
                    strTarget = line.replace('\n', '')


            with open("录音结果11.txt", "a", encoding="utf-8") as fp:
                fp.write(strTarget + '\n')

            print(strTarget)

            line = file.readline()

if __name__ == '__main__':
    # ConvertWenZi()  # 转文字
    ConvertWenHangHao()  # 整理行号